<?php

/**
 * User model
 *
 * @license     http://www.gnu.org/licenses/gpl-2.0.txt
 * @author      Mihály Kuprivecz <mkuprivecz@gmail.com>
 * @namespace   Beaver_Model
 */
class Default_Model_User extends Beaver_Model {
	/*protected $_validate = array (
		"username" => array(
			array(
				"type" => "stringLength",
				"attributes" => array(
					"min" => 3
				),
				"message" => "Default_Model_User_validate_username_length"
			),
			array(
				"type" => "alnum",
				"message" => "Default_Model_User_validate_username_alnum"
			)
		),
		"password" => array(
			array(
				"type" => "stringLength",
				"attributes" => array(
					"min" => 8
				),
				"message" => "Default_Model_User_validate_password_length"
			),
			array(
				"type" => "alnum",
				"message" => "Default_Model_User_validate_password_alnum"
			)
		)
	);*/
	
	public function findByUsername( $username )
	{
		if ( !is_string($username) )
		{
			throw new Beaver_Model_Exception("Username need to be string!");
		}
		$this->getMapper()->findByUsername($username);
		return $this;
	}
	
	public function eventLoggin()
	{
		if ( null === $this->username )
		{
			throw new Beaver_Model_Exception("Can't trigger the event, beacause no user setted in model!");
		}
		$this->getMapper()->setLastLogin();
		return $this;
	}
}
